<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 硬币 -->
    <script>
      var ways = function (n) {
        //取整  Math.sqrt 取出平方根
        let m = Math.floor(Math.sqrt(2 * n))
        if (n >= (m * (m + 1)) / 2) {
          return m
        } else {
          return m - 1
        }
      }
      console.log(ways(5))
      // console.log(ways(10))
    </script>
  </body>
</html>
